﻿#ifndef YIMAGEDRAWER_H
#define YIMAGEDRAWER_H

#include <QWidget>

class QGraphicsView;
class QGraphicsScene;
class QGraphicsItem;
class DrawTools;
namespace Y_Image_Drawer_GUI {
class YGraphicsItem;
}
class YImageDrawer : public QWidget
{
    Q_OBJECT

    enum Type{
        Rect = 1, Ellipse, Arrow, Pen, Mosaic, Text, Tip
    };
public:
    explicit YImageDrawer(const QImage& image, QWidget *parent = nullptr);
    inline void setType(int t) { type = Type(t); }
    void setViewCursor(const QCursor& cursor);

public:
    DrawTools* tools;
signals:

public slots:
    void thicknessChanged(int);
    void colorChanged(QColor);
    void redo();

protected:
    void createItem(const QPoint& pos);

private:
    QImage image;
    QGraphicsView* view;
    QGraphicsScene* scene;
    Type type;
    Y_Image_Drawer_GUI::YGraphicsItem* currentItem = nullptr;
    bool pressed = false;
    QPoint startPos;
    QList<QGraphicsItem*> items;

protected:
    bool eventFilter(QObject*, QEvent*) override;
};

#endif // YIMAGEDRAWER_H
